//
//  MedicineBoxTableViewController.m
//  myMedicine1.0
//
//  Created by pollysoft on 16/8/2.
//  Copyright © 2016年 microi. All rights reserved.
//

#import "MedicineBoxTableViewController.h"
#import "medicineTableViewCell.h"
#import "DrugMasterModel.h"
#define cellId @"MedicineBoxViewControllerCellId"

@interface MedicineBoxTableViewController ()<UITableViewDelegate,UITableViewDataSource,myMedicineBoxDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>

@property(strong, nonatomic) NSMutableArray *MedicineArray;
@property(weak, nonatomic) medicineTableViewCell *cell;

@end

@implementation MedicineBoxTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置navagation 标题字体的颜色
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName, nil]];
    
    self.tableView.rowHeight = 120.0;
    self.tableView.separatorStyle = NO;
    DrugMasterModel *CellModel0 = [[DrugMasterModel alloc]init];
    CellModel0.drugName = @"维他命E";
    CellModel0.drugPhoto = [UIImage imageNamed:@"维他命E.png"];
    
    DrugMasterModel *CellModel1 = [[DrugMasterModel alloc]init];
    CellModel1.drugName = @"盘尼西林";
    CellModel1.drugPhoto = [UIImage imageNamed:@"盘尼西林.png"];
    
    DrugMasterModel *CellModel2 = [[DrugMasterModel alloc]init];
    CellModel2.drugName = @"维他命C";
    CellModel2.drugPhoto = [UIImage imageNamed:@"维他命C.png"];
    
    DrugMasterModel *CellModel3 = [[DrugMasterModel alloc]init];
    CellModel3.drugName = @"维他命B";
    CellModel3.drugPhoto = [UIImage imageNamed:@"维他命B.png"];
    
    
    _MedicineArray = [NSMutableArray arrayWithObjects:CellModel0,CellModel1,CellModel2,CellModel3, nil];
    
    //注册一个cell的类告诉系统一会要使用它
    
    [self.tableView registerNib:[UINib nibWithNibName:@"medicineTableViewCell" bundle:nil] forCellReuseIdentifier:cellId];
    
    [self.tableView reloadData];
    
    
    
    
}
//懒加载
-(NSMutableArray *)MedicineArray{
    
    if (!_MedicineArray) {
        _MedicineArray = [[NSMutableArray alloc]init];
    }
    return _MedicineArray;
    
}

//-(medicineTableViewCell *)cell{
//
//    if (!_cell) {
//        _cell = [[medicineTableViewCell alloc]init];
//    }
//    return _cell;
//}

//实现代理协议的方法

-(void)presentToSellectMedicineImagePhotocontroller:(UIViewController *)viewController and:(NSInteger)cellRow{
    
    [self performSegueWithIdentifier:@"toMedicineListController" sender:nil];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _MedicineArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    //    myMedicineListTableViewCell *tableCell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
    
    _cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
    
    //    NSLog(@"见鬼了%@",indexPath);
    
    
    DrugMasterModel *MedicineModel = [_MedicineArray objectAtIndex:indexPath.row];
    
    _cell.medicineName.text = MedicineModel.drugName;
    //设置一个初始的图片
    [_cell.addMedicineImageButton setImage:MedicineModel.drugPhoto forState:UIControlStateNormal];
    
    //    [cell.addMedicineImageButton setBackgroundColor:[UIColor redColor]];
    
    
    
    //委托代理给myMedicineListTableViewController
    _cell.medicinePhotoDelegate = self;
    _cell.viewController = self;
    _cell.cellRow = indexPath.row;
    return _cell;
    
}


/*
 // Override to support conditional editing of the table view.
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the specified item to be editable.
 return YES;
 }
 */

/*
 // Override to support editing the table view.
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
 if (editingStyle == UITableViewCellEditingStyleDelete) {
 // Delete the row from the data source
 [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
 } else if (editingStyle == UITableViewCellEditingStyleInsert) {
 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
 }
 }
 */

/*
 // Override to support rearranging the table view.
 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
 }
 */

/*
 // Override to support conditional rearranging of the table view.
 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the item to be re-orderable.
 return YES;
 }
 */

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
